package com.sd.coupon;

import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.sd.coupon.util.GsonUtil;
import com.taobao.api.ApiException;
import com.taobao.api.DefaultTaobaoClient;
import com.taobao.api.TaobaoClient;
import com.taobao.api.request.TbkDgItemCouponGetRequest;
import com.taobao.api.request.TbkItemGetRequest;
import com.taobao.api.response.TbkDgItemCouponGetResponse;

public class TaobaoMain {

    public static void main(String[] args) throws ApiException {


        TaobaoClient client = new DefaultTaobaoClient("http://gw.api.taobao.com/router/rest", "25334735", "8468edcb10074eed0c65e0f84698c5aa");



//        TbkItemInfoGetRequest req = new TbkItemInfoGetRequest();
//        req.setNumIids("38012241391");
//        req.setPlatform(2L);
//        req.setIp("tech.xyauto.com");
//        TbkItemInfoGetResponse rsp = client.execute(req);
//        System.out.println(rsp.getBody());
//
//
//        TaobaoClient client = new DefaultTaobaoClient(url, appkey, secret);
//        ItemSellerGetRequest req = new ItemSellerGetRequest();
//        req.setFields("num_iid,title,nick,price,approve_status,sku");
//        req.setNumIid(38012241391);
//        ItemSellerGetResponse rsp = client.execute(req, sessionKey);
//        System.out.println(rsp.getBody());


//        TbkItemGetRequest req = new TbkItemGetRequest();
//        req.setFields("user_type,num_iid,title,pict_url,small_images,reserve_price,zk_final_price,user_type,provcity,item_url,seller_id,volume,nick");
//        req.setQ("女装");
//        req.setCat("16,18");
//        req.setItemloc("杭州");
//        req.setSort("tk_rate_des");
//        req.setPageNo(123L);
//        req.setPageSize(1L);
//        TbkItemGetResponse rsp = client.execute(req);
//        System.out.println(rsp.getBody());

        //类目
//        AlibabaWholesaleCategoryGetRequest

        //获取 优惠券
//        TbkDgItemCouponGetRequest req = new TbkDgItemCouponGetRequest();
//        req.setAdzoneId(67776250488L);
//        req.setPlatform(2L);
////        req.setCat("16");
//        req.setPageSize(2L);
//        req.setQ("男装");
//        req.setPageNo(1L);
//        TbkDgItemCouponGetResponse rsp = client.execute(req);
//
//        JsonObject returnData = new JsonParser().parse(rsp.getBody()).getAsJsonObject();
//        JsonArray arr = returnData.get("tbk_dg_item_coupon_get_response").getAsJsonObject().get("results").getAsJsonObject().get("tbk_coupon").getAsJsonArray();
//        for (int i = 0; i < arr.size(); i++) {
//            System.out.println(arr.get(i));
//            ItemCoupon coupon = GsonUtil.parseJsonWithGson(arr.get(i).toString(),ItemCoupon.class);
//            System.out.println(coupon);
//        }

//        System.out.println(rsp.getBody());
//        req.setPlatform(1L);
//        req.setCat("16,18");
//        req.setPageSize(10L);
//        req.setQ("装");
//
//        TbkDgItemCouponGetResponse rsp = client.execute(req);
//        System.out.println(rsp.getErrorCode());
//        System.out.println(rsp.getMessage()+"))"+rsp.getBody());
//        List<TbkDgItemCouponGetResponse.TbkCoupon> lisst = rsp.getResults();
//
//        for (TbkDgItemCouponGetResponse.TbkCoupon t:
//             lisst) {
//            System.out.println(t.toString());
//        }


    }
}
